<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/************************ BEGIN: AUCTION ************************/
/**
 * get_detail_url_for_auction()
 */
if (!function_exists('get_detail_url_for_auction')) {

    function get_detail_url_for_auction($item){
        $url = '';
        if (!empty($item['id'])) {
            $url = PATH_URL. 'chi-tiet-dau-gia/'.$item['id'];
        }
        return $url;
    }
}

/**
 * get_image_url_for_auction()
 */
if (!function_exists('get_image_url_for_auction')) {

    function get_image_url_for_auction($item,$image_type='small'){
        $url = '';
        if (!empty($item)) {
			switch($image_type){
				case 'small':
					$image_key = 'image_small';
					$folder = '160x146';
					break;
				case 'large':
					$image_key = 'image_large';
					$folder = '323x213';
					break;
			}
			if(!empty($folder) && $item[$image_key]){
				$url = PATH_URL. 'uploads/auction/image/'.$folder.'/'.$item[$image_key];
			}
        }
        return $url;
    }
}

/**
 * get_price_for_auction()
 */
if (!function_exists('get_price_for_auction')) {

    function get_price_for_auction($item){
        $html = '';
        if (!empty($item['price_vn'])) {
			$html = number_format($item['price_vn'], 0, ',', '.');
        }
        return $html;
    }
}
/************************ END: AUCTION ************************/


/************************ BEGIN: PRODUCT ************************/
/**
 * get_detail_url_for_product()
 */
if (!function_exists('get_detail_url_for_product')) {

    function get_detail_url_for_product($item){
        $url = '';
        if (!empty($item['id'])) {
            $url = PATH_URL. 'mua-hang/chi-tiet-san-pham/'.$item['id'];
        }
        return $url;
    }
}

/**
 * get_image_url_for_product()
 */
if (!function_exists('get_image_url_for_product')) {

    function get_image_url_for_product($item,$image_type='small'){
        $url = '';
        if (!empty($item)) {
			switch($image_type){
				case 'small':
					$image_key = 'image_small';
					$folder = '160x146';
					break;
				case 'large':
					$image_key = 'image_large';
					$folder = '323x213';
					break;
			}
			if(!empty($folder) && $item[$image_key]){
				$url = PATH_URL. 'uploads/product/image/'.$folder.'/'.$item[$image_key];
			}
        }
        return $url;
    }
}

/**
 * get_price_for_product()
 */
if (!function_exists('get_price_for_product')) {

    function get_price_for_product($item){
        $html = '';
        if (!empty($item['price_vn'])) {
			$html = number_format($item['price_vn'], 0, ',', '.');
        }
        return $html;
    }
}

/**
 * get_price_for_product()
 */
if (!function_exists('get_coin_by_price_for_product')) {

    function get_coin_by_price_for_product($item,$format=true){
        $html = '';
        if (!empty($item['price_vn'])) {
			$coin_convert = $item['price_vn']/20000*10;
			if($format){
				$html = number_format($coin_convert, 0, ',', '.');
			} else {
				$html = $coin_convert;
			}
        }
        return $html;
    }
}
/************************ END: PRODUCT ************************/